	var customer_array = new Array();
	var customer_record = new Array();
	var customer_cnt = 0;
	var customer_search_type = 0; // 0 = Default, 1 = Email, 2 = ID
	var customer_field = "";
	var customer_remove_if_no_data = 0;
	var customer_add_url = "";
	
	function set_customer( value, value2 )
	{
		if ( customer_search_type == 0 )
		{
			if ( document.getElementById('cus_username') )
			{
				if(document.getElementById("report_customer"))
				{
					document.getElementById("report_customer").value = value;
				}
				else
				{
					document.getElementById('cus_username').value = value;
				}
				
				if(document.getElementById("customer_list"))
				{
					document.getElementById("customer_list").innerHTML="";
				}
				
			}
			else
			{
				customer_field.value = value;	
			}
			
			// Check for address
			if ( document.getElementById("pay_receiver_address") )
			{
				document.getElementById("pay_receiver_address").value = value2;
			}
		}
		else if ( customer_search_type == 1 )
		{
			if ( document.getElementById('email_toname') )
			{
				document.getElementById('email_to').value = value;
			}
			else
			{
				customer_field.value = value;
			}
			
			if ( document.getElementById('email_toname') )
			{
				document.getElementById('email_toname').value = value2;
			}
			
			document.getElementById('customer_list').innerHTML = "";			
		}
		else if ( customer_search_type == 2 )
		{
		//	if ( document.getElementById('cus_id') )
		//	{
		//		document.getElementById('cus_id').value = value;
		//	}
		//	else
			{
				customer_field.value = value;
				
				if(customer_field.name=="cus_id") 
				{	
					document.getElementById("customer_list").innerHTML="";
				}
				else if(customer_field.name=="cus_member_id")
				{
					document.getElementById("customer_list_1").innerHTML="";
				}
			}
			
			// Check for address
			if ( document.getElementById("pay_receiver_address") )
			{
				document.getElementById("pay_receiver_address").value = value2;
			}
		}
	}
	
	function print_customer_row()
	{
		var i = customer_cnt;
		
		if ( customer_array.length-1 <= i )
		{
			document.getElementById("customer_list_loading").innerHTML = "";
			return false;
		}
		
		customer_record = customer_array[i].split("|");
		var row = document.createElement("tr");
				
		var cell1 = document.createElement("td");
		cell1.setAttribute("style", (i%2==0?"background: #F3F3F3;":"background: #FFFFFF;"));
		cell1.setAttribute("width", "15%");

		if ( customer_search_type == 0 )
		{
			cell1.innerHTML = "<input type='radio' id='cus_username' name='cus_username_search' value='"+customer_record[2]+"' onclick='set_customer(this.value,\""+customer_record[2]+"\");'> ";// + customer_record[0];
		}
		else if ( customer_search_type == 1 )
		{
			cell1.innerHTML = "<input type='radio' id='cus_username' name='cus_username_search' value='"+customer_record[2]+"' value2='"+customer_record[1]+"' onclick=set_customer(this.value,this.getAttribute('value'))> ";// + customer_record[0];
		}
		else if ( customer_search_type == 2 )
		{
			cell1.innerHTML = "<input type='radio' id='cus_username' name='cus_username_search' value='"+customer_record[2]+"' onclick='set_customer(this.value,\""+customer_record[2]+"\");'> ";//+ customer_record[0];
		}
		
		//row.appendChild(cell1);
		
		//var cell2 = document.createElement("td");
		//cell2.setAttribute("width", "25%");
		cell1.innerHTML += pms['customer_read'] == 1 ? "<a href='"+site_root_domain+"/?site=customer&act=show&id="+customer_record[0]+"'><b>"+customer_record[1]+"</b></a>" : "<b>" + customer_record[1] + "</b>";
		//row.appendChild(cell2);
		row.appendChild(cell1);
		
		var cell3 = document.createElement("td");
		cell3.setAttribute("style", (i%2==0?"background: #F3F3F3;":"background: #FFFFFF;"));
		cell3.setAttribute("width", "25%");
		cell3.innerHTML = customer_record[3];
		row.appendChild(cell3);
		
		var cell6 = document.createElement("td");
		cell6.setAttribute("style", "color: #999;"+(i%2==0?"background: #F3F3F3;":"background: #FFFFFF;"));
		cell6.setAttribute("width", "15%");
		cell6.innerHTML = customer_record[2];
		row.appendChild(cell6);

		/*var cell4 = document.createElement("td");
		cell4.setAttribute("style", (i%2==0?"background: #F3F3F3;":"background: #FFFFFF;"));
		cell4.setAttribute("width", "25%");
		cell4.innerHTML = customer_record[4];
		row.appendChild(cell4);*/
		
		var cell5 = document.createElement("td");
		cell5.setAttribute("style", "text-align: right;"+(i%2==0?"background: #F3F3F3;":"background: #FFFFFF;"));
		cell5.setAttribute("width", "20%");
		cell5.innerHTML = customer_record[4];
		row.appendChild(cell5);

		if ( ! document.getElementById("customer_list_tr") )
		{
			return false;	
		}
		
		document.getElementById("customer_list_tr").appendChild(row);

		customer_cnt++;
		
		setTimeout("print_customer_row()", 100);
	}
	
	function print_customer( data,customer_field )
    {
		customer_array = data.split("||||");
		
		customer_record = new Array();
		customer_cnt = 0;
       
	    var customer_html = "";
		customer_html += "<table width='100%' cellspacing='0' cellpadding='0' id='customer_list_table'><tbody id='customer_list_tr'>";
		customer_html += "</tbody></table><div id='customer_list_loading'>"+lang_loading+"</div>";
		
    	document.getElementById("customer_list").innerHTML = customer_html;
    
		if ( customer_array.length == 1 )
		{
			if ( customer_remove_if_no_data == 1 )
			{
				customer_field.value = "";	
			}
			
			document.getElementById("customer_list_loading").innerHTML = "<b><font color='red'>" + lang_no_result + "</font></b>";
		}
		else
		{
			print_customer_row();
		}
    }
	
	function customer_search( cus, search_type, remove_if_no_data )
    {
		customer_field = cus;
		
		customer_remove_if_no_data = remove_if_no_data;
		
		if ( search_type == 1 )
		{
			customer_search_type = 1;
		}
		else if ( search_type == 2 )
		{
			customer_search_type = 2;	
		}
		else
		{
			customer_search_type = 0;	
		}
		
		cus.value = trim(cus.value);
		
    	if ( cus.value )
        {

           if ( customer_search_type == 0 )
		   {
			   	var url = site_root_domain + "/?site=customer&act=search&is_ajax=1&cus_id="+cus.value+customer_add_url;
		   }
		   else
		   {
			  	var url = site_root_domain + "/?site=customer&act=search&is_ajax=1&cus_id="+cus.value+customer_add_url;
		   }

           AjaxRequest.get(
            {
                'url':''+url+''
                ,'onLoading':function(req){ document.getElementById("customer_list").innerHTML = lang_loading; }
                ,'onSuccess':function(req){print_customer(req.responseText,customer_field);  }
            }
            );
        }
        else
        {
        	document.getElementById("customer_list").innerHTML = "";
        }
    }
	
